unit AcroMultiStringWidestringAdapter;

interface
uses
  AcroMultiUtils,Windows,TrapAPI;

implementation
const
  DesignLocalID=950;

procedure MyLStrFromWStr(var Dest: AnsiString; const Source: WideString);
begin
  Dest:=AcroMultiUtils.UnicodeDecode(Source,DesignLocalID);
end;

procedure MyLStrFromPWChar(var Dest: AnsiString; Source: PWideChar);
begin
  Dest:=AcroMultiUtils.UnicodeDecode(Source,DesignLocalID);
end;

procedure MyWStrFromLStr(var Dest: WideString; const Source: AnsiString);
begin
  Dest:=AcroMultiUtils.UnicodeEncode(Source,DesignLocalID);
end;

procedure MyWStrFromPChar(var Dest: WideString; Source: PAnsiChar);
begin
  Dest:=AcroMultiUtils.UnicodeEncode(Source,DesignLocalID);
end;

function MyLoadResString(ResStringRec: PResStringRec): string;
var
  WS:WideString;
  nLen:integer;
begin
  if ResStringRec = nil then Exit;
  if ResStringRec.Identifier < 64*1024 then
  begin
    Setlength(WS,4096);
    nLen:=LoadStringW(FindResourceHInstance(ResStringRec.Module^),
      ResStringRec.Identifier, PWideChar(WS), Length(WS));
    SetLength(WS,nLen);
  end
  else
    WS:= PWideChar(ResStringRec.Identifier);
  Result:=AcroMultiUtils.UnicodeDecode(WS,DesignLocalID);
//  Result:=AcroMultiResource.ResourceStorage.GetDisplayValue(Result);
end;

function MyGetLocaleInfo(Locale: LCID; LCType: LCTYPE; lpLCData: PChar; cchData: Integer): Integer;
var
  S:string;
begin
  TrapAPI.TrapStorage.UnTrap(kernel32,'GetLocaleInfoA',@MyGetLocaleInfo);
  Result:=0;
  S:='950'+#0;
  if (lpLCData<>nil) and (cchData>=4) then
  begin
    {$IFDEF MSWindows}
    Move(S[1],lpLCData^,4);
    {$ELSE}
    Move(PChar(S)^,lpLCData^,4);
    {$ENDIF}
  end;
end;

function MyReadWChar(var t: TTextRec): WideChar;
var
  WC:WideChar;
begin
  WC:='A';
  Result:=WC;
end;

procedure MyReadWString(var t: TTextRec; var s: WideString);
begin
  S:='A';
end;

//
initialization
  TrapAPI.TrapStorage.Trap(kernel32,'GetLocaleInfoA',@MyGetLocaleInfo);
//  TrapAPI.TrapStorage.Trap('rtl70.bpl','@System@@ReadWChar$qqrr15System@TTextRec',@MyReadWChar);
//  TrapAPI.TrapStorage.Trap('rtl70.bpl','@@System@@ReadWString$qqrr15System@TTextRecr17System@WideString',@MyReadWString);
//  TrapAPI.TrapStorage.Trap('rtl70.bpl','@System@@LStrFromWStr$qqrr17System@AnsiStringx17System@WideString',@MyLStrFromWStr);
//  TrapAPI.TrapStorage.Trap('rtl70.bpl','@System@@LStrFromPWChar$qqrr17System@AnsiStringpb',@MyLStrFromPWChar);

//  TrapAPI.TrapStorage.Trap('rtl70.bpl','@System@@WStrFromLStr$qqrr17System@WideStringx17System@AnsiString',@MyWStrFromLStr);
//  TrapAPI.TrapStorage.Trap('rtl70.bpl','@System@@WStrFromPChar$qqrr17System@WideStringpc',@MyWStrFromPChar);

  TrapAPI.TrapStorage.Trap('rtl70.bpl','@System@LoadResString$qqrp20System@TResStringRec',@MyLoadResString);
finalization
  TrapAPI.TrapStorage.UnTrap('rtl70.bpl','@System@LoadResString$qqrp20System@TResStringRec',@MyLoadResString);

//  TrapAPI.TrapStorage.UnTrap('rtl70.bpl','@System@@WStrFromPChar$qqrr17System@WideStringpc',@MyWStrFromPChar);
//  TrapAPI.TrapStorage.UnTrap('rtl70.bpl','@System@@WStrFromLStr$qqrr17System@WideStringx17System@AnsiString',@MyWStrFromLStr);

//  TrapAPI.TrapStorage.UnTrap('rtl70.bpl','@System@@LStrFromPWChar$qqrr17System@AnsiStringpb',@MyLStrFromPWChar);
//  TrapAPI.TrapStorage.UNTrap('rtl70.bpl','@System@@LStrFromWStr$qqrr17System@AnsiStringx17System@WideString',@MyLStrFromWStr);

//  TrapAPI.TrapStorage.UnTrap('rtl70.bpl','@System@@ReadWChar$qqrr15System@TTextRec',@MyReadWChar);
  TrapAPI.TrapStorage.UnTrap(kernel32,'GetLocaleInfoA',@MyGetLocaleInfo);
end.
